package MyApp.Model.proxy
{
	import mx.controls.Alert;
	import mx.rpc.AbstractOperation;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;
	
	import org.puremvc.as3.patterns.proxy.Proxy;
	
	import util.Constants;
	import util.GDUtil;
	
	public class ReportProxy extends Proxy
	{
		public static const NAME:String="ReportProxy";
		public static const ERROR_MESSAGE_RETURN:String=GDUtil.getUID();
		public static const GROUP_LOAD_OK:String=GDUtil.getUID();
		public static const REPORT1_LOAD_OK:String=GDUtil.getUID();
		public static const REPORT2_LOAD_OK:String=GDUtil.getUID();
		public function ReportProxy(proxyName:String=null, data:Object=null)
		{
			super(proxyName, data);
		}
		private var remote:RemoteObject;
		protected function get reportService():RemoteObject{
			if(remote==null){
				remote=GDUtil.remoteObject();
				remote.destination = Constants.SER_REPORT;
			}
			return remote;
		}
		public function loadGroupList():void{
			var ope:AbstractOperation=reportService.getOperation("getWellGroupList");
			var hd:Function=function (e:ResultEvent):void{
				facade.sendNotification(GROUP_LOAD_OK,e.result);
				ope.removeEventListener(ResultEvent.RESULT,hd);
			};
			ope.addEventListener(ResultEvent.RESULT,hd);
			ope.addEventListener(FaultEvent.FAULT,listFault);
			ope.send();
		}
		public function loadReport1List(obj:Object):void{
			var groupId:int=obj.groupId;
			var year:int=obj.year;
			var timeType:int=obj.timeType;
			var ope:AbstractOperation=reportService.getOperation("getSingleWellGroupReport");
			var hd:Function=function (e:ResultEvent):void{
				facade.sendNotification(REPORT1_LOAD_OK,e.result);
				ope.removeEventListener(ResultEvent.RESULT,hd);
			};
			ope.addEventListener(ResultEvent.RESULT,hd);
			ope.addEventListener(FaultEvent.FAULT,listFault);
			ope.send(groupId,year,timeType);
		}
		public function loadReport2List(obj:Object):void{
			var productType:int=obj.productType;
			var year:int=obj.year;
			var timeType:int=obj.timeType;
			var ope:AbstractOperation=reportService.getOperation("getMoreWellGroupReport");
			var hd:Function=function (e:ResultEvent):void{
				facade.sendNotification(REPORT2_LOAD_OK,e.result);
				ope.removeEventListener(ResultEvent.RESULT,hd);
			};
			ope.addEventListener(ResultEvent.RESULT,hd);
			ope.addEventListener(FaultEvent.FAULT,listFault);
			ope.send(productType,year,timeType);
		}
		private function listFault(e:FaultEvent):void{
			this.sendNotification(ERROR_MESSAGE_RETURN,{message:"数据获取失败"});
			Alert.show("数据获取失败");
		}
	}
}